package com.itheima.集合;

import java.util.LinkedList;
/*1.手写栈容器,2.手写队列容器*/
public class 手写一个栈容器 {
    public static void main(String[] args) {
        MyTrack  stack=new MyTrack();
        stack.push("hello...");
        stack.push("world...");
        stack.push("you...");
        stack.push("where...");
        System.out.println(stack.toString());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println("....................");
        MyDuiLie dl=new MyDuiLie();
        dl.push("hello...");
        dl.push("world...");
        dl.push("you...");
        dl.push("where...");
        System.out.println(dl.toString());
        System.out.println(dl.pop());
        System.out.println(dl.pop());
        System.out.println(dl.pop());
        System.out.println(dl.pop());
    }
}


class MyTrack{
    private  LinkedList<String> list=new LinkedList<String>();

    public String  pop(){
        String last = list.removeFirst();
        return last;
    }
    public void push(String s){
        list.addFirst(s);
        }

    @Override
    public String toString() {
        return "MyTrack{" +
                "list=" + list +
                '}';
    }
}
class MyDuiLie{
    private  LinkedList<String> list=new LinkedList<String>();
    public String  pop(){
        String last = list.removeLast();
        return last;
    }

    @Override
    public String toString() {
        return "MyDuiLie{" +
                "list=" + list +
                '}';
    }

    public void push(String s){
        list.addFirst(s);
    }
}